package io.hxci.modules.stu.controller;

import io.hxci.common.utils.PageUtils;
import io.hxci.common.utils.R;
import io.hxci.modules.stu.domain.EvalApply;
import io.hxci.modules.stu.domain.EvalRecord;
import io.hxci.modules.stu.service.EvalApplyService;
import io.hxci.modules.stu.service.EvalRecordService;
import io.hxci.modules.sys.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController //注解
@RequestMapping("guide")
public class ApplayController  extends AbstractController {
    @Autowired
    EvalApplyService applyService;
    @Autowired
    EvalRecordService recordService;
   //显示加分申请的显示全部
    @RequestMapping("applay")
    public R applay(@RequestParam Map<String, Object> params){
        Long sid = getUserId();
        PageUtils page = applyService.queryPage(sid,params);
        return R.ok().put("page", page);
    }

    //显示加分申请的显示一条
    @RequestMapping("applayOne")
    public R applayOne(Integer id){

        EvalApply apply =applyService.applayOne(id);
        return R.ok().put("apply", apply);
    }

    //审批一条数据
    @RequestMapping("applaySave")
    public R applaySave(@RequestBody EvalApply apply){




        applyService.updateById(apply);

        if(apply.getStatus() ==1){
            EvalRecord record = new EvalRecord();
            record.setKindid(apply.getBtype());
            record.setStuid(apply.getSid());
            record.setScore(apply.getScore());
            record.setAid(apply.getId());
            record.setSign(1);
            recordService.save(record);
        }
        return R.ok();
    }



    @RequestMapping("clazzQuery")
    public R clazzQuery(@RequestParam Map<String, Object> params){
        Long sid = getUserId();
        PageUtils page = applyService.clazzQuery(sid,params);
        return R.ok().put("page", page);
    }


    @RequestMapping("stuQuery")
    public R stuQuery(@RequestParam Map<String, Object> params){
        String cid =(String)params.get("cid");
        PageUtils page = null;
        if(("").equals(cid)){
            Long sid = getUserId();
            page = applyService.stuQueryByGuid(sid,params);
        }else{
             page = applyService.stuQuery(cid,params);
        }

        return R.ok().put("page", page);
    }

}
